#! /usr/bin/python3
# -*- coding: UTF-8 -*-
  
'''※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
File Name: base.py
Author: GID5564
Description: 
Version: 1.0
Created Time: 15/05/24-15:40:04
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※'''
import sys
import cv2
from cvs import *
import pyttsx3
from pyttsx3.voice import Voice

sys.path.append("..")
from func import install_and_import


def _get_chinese_voice(engine: pyttsx3.engine.Engine) -> Voice:
    voices = engine.getProperty("voices")
    for voice in voices:
        if "Chinese" in voice.name or "Mandarin" in voice.name.title():
            return voice
 
    raise RuntimeError(f"No Chinese voice found among {voices}")  
    
#中文不行
def text_to_speech(text, output_file='output.mp3'):
    # 初始化 TTS 引擎
    engine = pyttsx3.init()
 
    # 设置语音参数
    engine.setProperty('rate', 150)  # 语速，可以调整
 
    engine.setProperty('volume', 1)  # 音量，取值范围 0.0 到 1.0
 
    chinese_voice = _get_chinese_voice(engine)
    engine.setProperty("voice", chinese_voice.id)
 
    # 将文本转换为语音
    engine.save_to_file(text, output_file)
    #播报
    engine.say(text)

    # 关闭 TTS 引擎
    engine.runAndWait()


#实现拍照

    


























    
    
    
    
    
    
    
    
    
    
    
    